package com.tff.gmall.redisson.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Fafa Tuo
 * @version 1.0
 * @date 2021/5/21 23:26
 */
public class LeetCodeTest {

    public static void main(String[] args) {

        int [] nums = new int[]{3,2,4};
        int[] ints = twoSums(nums, 6);
        System.out.println(" "+ints[0]+"   "+ints[1]);

        System.out.println(test());

    }



    public static int[] twoSum(int[] nums, int target) {
        int []index = new int[2];
        K:for(int i=0;i<nums.length;i++){
            int k = i;
            for (int j=i+1;j<nums.length;j++){
                if(nums[i]+nums[j] == target){

                    index[0] = k;
                    index[1] = j;
                    break K;
                }
            }
        }
        return  index;
    }
    public static int[] twoSums(int []nums,int target){
        Map<Integer,Integer> map = new HashMap<>(nums.length-1);
        //先放入第一个元素
        map.put(nums[0],0);
        //循环从第二个元素开始比较
        for (int i = 1;i<nums.length;i++){
            int val = target-nums[i];
            if(map.containsKey(val)){
                return new int[]{map.get(val),i};


            }
            map.put(nums[i],i);
        }

        return null;
    }

    public static int test(){
        int str = 219+97+100+100+74+15+100+100+15+75+100;
        return str;
    }
}


